<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<base href="<?= base_url(1); ?>" />
<link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
<script src="js/time.js?"></script>
<script charset="utf-8" src="edit/kindeditor.js"></script>
<script charset="utf-8" src="edit/lang/zh_CN.js"></script>
<script charset="utf-8" src="edit/plugins/code/prettify.js"></script>
<script type="text/javascript">

	function addp()
	{
	    //得到当前数组的长度
		var i = document.getElementsByName("childP").length;
		//alert(i);
		
	    //策略号为当前最大的编号 加1
	    var obj = document.getElementById("strategyid"+(i-1));
	    var showValue= 0;
	    if(null != obj)
	    {
	        showValue = obj.value;
	    }
	    showValue = parseInt(showValue) + 1;
		//alert(showValue);
	    var strOption='';
	    var modList = <?=json_encode($moduleList)?>;
		//alert(modList);
	    for(var one in modList)
	    {
	    	strOption += '<option value="'+modList[one]['tableenum']+'" >'+modList[one]['des']+'</option>';
	    }
	    //alert(strOption);
	    str = '<center><table id ="p'+i+'" name="childP" border="0" width="100%">'+
	  		      '<tr>'+
		        '<td>&nbsp;</td>'+
		        '<td>&nbsp;</td>'+
		      '</tr>'+
		      '<tr>'+
		        '<td>&nbsp;<?= translate('ACTIVITY_GROUPSTATEGY_MODULENAME') ?>'+
		          '</td>'+
		        '<td>'+
					'<select  name="row[module]['+i+'][tableenum]" id="tableenum'+i+'" onChange="getStrategyId('+i+')">'+
					'<option value=""><?= translate('PLASE_SELECT') ?></option>'+
					strOption+
	   	      		'</select>'+
		        '</td>'+
		      '</tr>'+
		      '<tr>'+
		        '<td>&nbsp;<?= translate('ACTIVITY_STRATEGY_STRAGEGYNAME') ?>'+
		          '</td>'+
		        '<td>'+
			        '<select  name="row[module]['+i+'][strategyid]" id="strategyid'+i+'">'+
					'<option value="">&nbsp;<?= translate('PLASE_SELECT') ?></opton>'+
		      			'</select>'+
		        '</td>'+
		      '</tr>'+
		      '<tr>'+
		        '<td>&nbsp;<?= translate('ACTIVITY_MODULE_DES') ?>'+
		          '</td>'+
		        '<td >'+
		        	'<textarea cols="70" rows="13" name="row[module]['+i+'][des]" id="contents'+i+'" ></textarea>'+
		        	//<textarea cols="70" rows="13" name="row[module][0][des]" id="contents"></textarea>
		            //'<input type="text"  name="row[module]['+i+'][des]" id="des'+i+'"/>'+
		        '</td>'+
		    '</table></center>';
	    //alert(str);	
	    $("#add").append(str);
	    //$("#add").after(str);
	    autocomplete();
	    $("#contents"+i).formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
	    //$("#strategyid"+i).formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
		//$("#des"+i).formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: "^(0\.\d*[1-9])|(1)$", onerror: '<?= translate('C_NUM_BETTWEEN_0_AND_1') ?>'});

		getEdit(i)
		 
		}
	function removep()
	{
		var i = document.getElementsByName("childP").length-1;
	    //alert(i);
	    if (i > 0)
	    {
	        //alert(i);
	        $("#p" + i).remove();
	        //i--;
	    }
	}
	
	function getStrategyId(i)
	{
	
		var tableenum = $('#tableenum'+i).val();
		//alert(tableenum);
		//alert(i);
		//判断选的模块名是否合法 之前是否已经选择过了？

		var msl = <?=json_encode($modStrategyList)?>;
		var strOption = '';
		for(var one in msl[tableenum])
	    {
	    	strOption += '<option value="'+one+'" >'+msl[tableenum][one]+'</option>';
	    }
		//alert(strOption); 
		$('#strategyid'+i).html(strOption);
	} 
	
	function checkValid()
	{
		return true;
		var roleId = document.getElementById("role_id").value;
		//alert(roleId);
		if('-1' == roleId)
		{
			alert("error area num");
			return false;
		}else if('-2' == roleId)
		{
			alert("can not find rolename in this area");
			return false;
		}
		else
		{
			//alert("success");
			return true;
		}
	}
	
	function getModuleList()
	{
		var modList = <?=json_encode($moduleList)?>;
		//alert(modList);
		var strOption = '';
	    for(var one in modList)
	    {
	    	strOption += '<option value="'+modList[one]['tableenum']+'" >'+modList[one]['des']+'</option>';
	    }
	    return strOption;
	}

	   KindEditor.ready(function(K) {
           var editor1 = K.create('textarea[id="contents0"]', {
               //width : w,
               cssPath: 'edit/plugins/code/prettify.css',
               uploadJson: 'edit/php/upload_json.php',
               fileManagerJson: 'edit/php/file_manager_json.php',
               allowFileManager: true,
               urlType: "domain",
               afterCreate: function() {
                   var self = this;
                   K.ctrl(document, 13, function() {
                       self.sync();
                       K('form[name=rowForm]')[0].submit();
                   });
                   K.ctrl(self.edit.doc, 13, function() {
                       self.sync();
                       K('form[name=rowForm]')[0].submit();
                   });
               }
           });
           prettyPrint();
       });

	function getEdit(i)
	{
		//alert(i);

	           var editor1 = KindEditor.create('textarea[id="contents'+i+'"]', {
	               //width : w,
	               cssPath: 'edit/plugins/code/prettify.css',
	               uploadJson: 'edit/php/upload_json.php',
	               fileManagerJson: 'edit/php/file_manager_json.php',
	               allowFileManager: true,
	               urlType: "domain",
	               afterCreate: function() {
	                   var self = this;
	                   K.ctrl(document, 13, function() {
	                       self.sync();
	                       K('form[name=rowForm]')[0].submit();
	                   });
	                   K.ctrl(self.edit.doc, 13, function() {
	                       self.sync();
	                       K('form[name=rowForm]')[0].submit();
	                   });
	               }
	           });
	           prettyPrint();

	}	
</script>

</head>
<body>
<?php include(VIEWPATH . 'common/main_header.php'); ?>
<?php
    		//print_r($moduleList);
    		//print_r($modStrategyList); 
    	?>
    	
    	 <?php
    	 	 $strOP = "";
              foreach ($moduleList as $key => $value)
              {
              	//echo " key = $key  value = ".$value['des'];
              	//print_r($value);
              	//$strOP .= "<option value='$key' >{$value[des]}</option>";
              	$strOP .= "".$key.$value['des'];
              }
           //echo " strop = $strOP ";
         ?>
    	
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
            
	            <tr>
			      <td><?= translate('SELECT_AREA') ?>:</td>
			      <td><?= $arealist ?></td>		        
			    </tr>
			    <!--  
                <tr><td><?= translate('ACTIVITY_GROUP_NAME') ?>:</td>
                <td><input type="text" name="row[activityname]" id="activityname" size="25" /></td></tr>
                -->
                <tr><td><?= translate('STARTTIME') ?>:</td><td>
                	<input type="text" name="row[starttime]" id="starttime" size="25" onClick="SelectDate(this,'yyyy-MM-dd hh:mm:ss',0,10)"/>
                </td></tr>
                <tr><td><?= translate('ENDTIME') ?>:</td><td>
                	<input type="text" name="row[endtime]" id="endtime" size="25" onClick="SelectDate(this,'yyyy-MM-dd hh:mm:ss',0,10)"/>
                </td></tr>               
		      
              <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
              
 

              <p id="add" name="childP">
		  		      <tr>
			        <td>&nbsp;</td>
			        <td>&nbsp;</td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_GROUPSTATEGY_MODULENAME') ?>
			          </td>
			        <td>
						<select  name="row[module][0][tableenum]" id="tableenum0" onChange="getStrategyId(0)">
							<option value=""><?= translate('PLASE_SELECT') ?></option>
							<script type="text/javascript">
								document.write(getModuleList());
							</script>
           	      		</select>
			        </td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_STRATEGY_STRAGEGYNAME') ?>
			          </td>
			        <td>
				        <select  name="row[module][0][strategyid]" id="strategyid0">
						<option value="">&nbsp;<?= translate('PLASE_SELECT') ?></opton>
	   	      			</select>
			        </td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_MODULE_DES') ?>
			          </td>
			        <td >
			            <!--  <input type="text"  name="row[module][0][des]" id="des0"/> -->
			            <textarea cols="70" rows="13" name="row[module][0][des]" id="contents0"></textarea>
			        </td>
			    </p>

               
             
		      <tr>
		        <td><div align="center">
		            <input type="button" onClick="addp()" value="<?= translate('ADD_ONE') ?>" />
		          </div></td>
		        <td><div align="center">
		            <input type="button" onClick="removep()" value="<?= translate('REMOVE_ONE') ?>" />
		        </div></td>
		      </tr>
		      
              <tr><td></td>
                <td><input type="submit" value="<?= translate('SUBMIT') ?>" id="submit" onClick="return checkValid()"/> 
                <input type="reset" value="<?= translate('RESET') ?>" id="reset"/>
                </td>
              </tr>
              
            </table>
            
        </form>
<script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                //$("#strategyid").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#activityname").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#starttime").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$", onerror: '<?= translate('C_INVALID_TIME') ?>'});
                $("#endtime").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).regexValidator({regexp: "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$", onerror: '<?= translate('C_INVALID_TIME') ?>'});
                $("#contents0").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                //$("#num0").formValidator({empty: false, defaultvalue: '<?= translate('AREA_FORM_INPUT_OPENTIME') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
            });
        </script>
</body>
</html>
